<template>
	<view class="wrap">
		<view style="background-color: #fff;border-radius: 16rpx;">
			<u-cell-item title="车牌号" :value="bindCarPlate" :arrow="false" hover-class="none"></u-cell-item>
		</view>
		<view style="display: flex;align-items: center;justify-content: flex-end;margin: 10rpx 0;">
			<u-button @click="getLocal()" type="primary" size="mini">重新获取</u-button>
		</view>
		<view style="background-color: #fff;border-radius: 16rpx;margin-top: 20rpx;">
			<u-cell-item title="工地纬度" :value="model.inCarLat" :arrow="false" hover-class="none"></u-cell-item>
			<u-cell-item title="工地经度" :value="model.inCatLon" :arrow="false" hover-class="none"></u-cell-item>
		</view>
		<view style="padding: 0 30rpx;background-color: #fff;margin-top: 20rpx;">
			<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
				<u-form-item :label-position="labelPosition" label="工地名称" prop="constructionSiteName">
					<u-input :border="border" placeholder="请输入工地名称" v-model="model.constructionSiteName" type="text"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label="工地地址" prop="soilFieldNameAddr">
					<u-input :border="border" placeholder="请输入工地地址" v-model="model.soilFieldNameAddr" type="text"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label="施工单位" prop="implementationUnit">
					<u-input :border="border" placeholder="请输入施工单位" v-model="model.implementationUnit" type="text"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label="垃圾种类" prop="wasteTypeText">
					<u-input :border="border" type="select" :select-open="selectShow" v-model="model.wasteTypeText"
						placeholder="请选择垃圾种类" @click="selectShow = true"></u-input>
				</u-form-item>
				<u-form-item :label-position="labelPosition" label="运出量（吨）" prop="removalQuantity">
					<u-input :border="border" placeholder="请输入运出量（吨）" v-model="model.removalQuantity" type="text"></u-input>
				</u-form-item>
			</u-form>
		</view>
		<view style="margin-top: 30rpx;">
			<u-button @click="submit" type="primary">提交</u-button>
		</view>
		<u-select mode="single-column" :list="wasteTypeList" v-model="selectShow" @confirm="selectConfirm"></u-select>
	</view>
</template>

<script>
	export default {
		data() {
			let that = this;
			return {
				model: {
					"remark": "",
					"constructionSiteId": "",
					"constructionSiteName": "",
					"distance": "",
					"soilFieldName": "",
					"soilFieldNameAddr": "",
					"implementationUnit": "",
					"wasteType": 0,
					"removalQuantity": "",
					"transportationCompanyName": "",
					"transportationCompanyId": 0,
					"driverName": "",
					"driverId": 0,
					"driverPhone": "",
					"carId": "",
					"plate": "",
					"vehicleType": "",
					"plateColor": "",
					"soilFieldId": '',
					"cargoVolume": '',
					"enterpriseName": '',
					"soilVolumePrice": '',
					"constructionSiteCompanyId": '',
					"status": '',
					"jointOrderStatus": 0,
					"provinceCode": '',
					"provinceName": '',
					"cityCode": '',
					"cityName": '',
					"areaCode": '',
					"areaName": '',
					"townName": '',
					"townCode": '',
					"inCarLat": '',
					"inCatLon": '',
					
					wasteTypeText:''
				},
				
				rules: {
					name: [{
						required: true,
						message: '请输入姓名',
						trigger: 'blur',
					}, ],
					goodsType: [{
						required: true,
						message: '请选择商品类型',
						trigger: 'change',
					}],
				},
				selectStatus: 'close',
				actionSheetShow: false,
				pickerShow: false,
				selectShow: false,
				labelPosition: 'top',
				errorType: ['toast'],

				areaId: '',
				constructionSite: '',
				//垃圾类型
				wasteTypeList: [{
					'value': 0,
					'label': '装修垃圾'
				}, {
					'value': 1,
					'label': '工程渣土'
				}, {
					'value': 2,
					'label': '工程泥浆'
				}, {
					'value': 3,
					'label': '建筑材料'
				}, {
					'value': 4,
					'label': '拆除垃圾'
				}],
				
				bindCarPlate:''
			};
		},
		onLoad(opt) {
			this.areaId = opt.areaId
			this.bindCarPlate = getApp().globalData.bindCar.plate
			this.getArea()
			this.getLocal()
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
						this.$u.post("/driver/addOrder",this.model).then(res=>{
							if(res.code==200){
								let id = res.data.id
								// uni.redirectTo({
								// 	url:"/pages/order/detail/detail?id="+id
								// })
								uni.switchTab({
									url:"/pages/order/order"
								})
							}
						})
					} else {
						console.log('验证失败');
					}
				});
			},

			//获取施工工地信息
			getArea() {
				this.$u.get("/driver/constructionSitePage", {
					id: this.areaId
				}).then(res => {
					if (res.code == 200) {
						this.constructionSite = res.rows[0]
						this.model.constructionSiteId = this.constructionSite.id
						this.model.constructionSiteName = this.constructionSite.name
						this.model.soilFieldName = this.constructionSite.name
						this.model.soilFieldNameAddr = this.constructionSite.address
						this.model.implementationUnit = this.constructionSite.constructionCompany
						this.model.wasteType = this.constructionSite.cargoType
						this.model.wasteTypeText = this.constructionSite.cargoType
						this.model.removalQuantity = getApp().globalData.bindCar.carLoadBearing
						this.model.transportationCompanyName= getApp().globalData.transportationCompany.name //运输公司名称
						this.model.transportationCompanyId =  getApp().globalData.transportationCompany.id//运输公司id
						this.model.driverName= getApp().globalData.driverInfo.name //驾驶员姓名（基本信息提取驾驶员姓名）
						this.model.driverId=getApp().globalData.driverInfo.id //驾驶员驾驶员id（基本信息提取驾驶员id）
						this.model.driverPhone=getApp().globalData.driverInfo.phone //驾驶员手机号（基本信息提取驾驶员手机号）
						this.model.carId=getApp().globalData.bindCar.oldCarId//车辆carId
						this.model.plate=getApp().globalData.bindCar.plate //车牌号
						this.model.vehicleType= getApp().globalData.bindCar.vehicleType//车辆类型-必填:1.五小工程车 2.商砼车 3.渣土车 4.泥浆车 5.泵车 6.挖机
						this.model.plateColor= getApp().globalData.bindCar.vehicleColor//车牌颜色
						
						this.model.provinceCode = this.constructionSite.provinceCode
						this.model.provinceName = this.constructionSite.provinceName
						this.model.cityCode = this.constructionSite.cityCode
						this.model.cityName = this.constructionSite.cityName
						this.model.areaCode = this.constructionSite.areaCode
						this.model.areaName = this.constructionSite.areaName
						this.model.townCode = this.constructionSite.townCode
						this.model.townName = this.constructionSite.townName
						
						console.log(getApp().globalData.bindCar)
					}
				})
			},

			// 选择商品类型回调
			selectConfirm(e) {
				console.log(e)
				if(e){
					this.model.wasteType = e[0].value
					this.model.wasteTypeText = e[0].label
				}
			},
			
			//获取车辆经纬度
			getLocal(){
				console.log("ss")
				let that = this
				uni.getLocation({
					type: 'gcj02',
					success: function (res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						that.model.inCarLat = res.latitude
						that.model.inCatLon = res.longitude
					}
				});
			}

		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}
</style>